package cn.kgc.airmanage.demo.service;



import cn.kgc.airmanage.demo.mapper.AirqualityindexMapper;
import cn.kgc.airmanage.demo.mapper.ViewdistrictairMapper;
import cn.kgc.airmanage.demo.pojo.Airqualityindex;
import cn.kgc.airmanage.demo.pojo.Viewdistrictair;
import cn.kgc.airmanage.demo.pojo.ViewdistrictairExample;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service

public class AirqualityServiceImpl implements  AirqualityService {
    @Resource
    AirqualityindexMapper mapper1;
    @Resource
    ViewdistrictairMapper mapper2;


    @Override

    public PageInfo<Viewdistrictair> SelectAllBydistrictId(Integer districtid, Integer pageNum, Integer PageSize) {
        PageHelper.orderBy("monitortime desc");
        PageHelper.startPage(pageNum,PageSize);

        ViewdistrictairExample example=new ViewdistrictairExample();
        ViewdistrictairExample.Criteria criteria=example.createCriteria();
        if(districtid!=0){
            criteria.andDistrictidEqualTo(districtid);
            List<Viewdistrictair> list=mapper2.selectByExample(example);
            PageInfo<Viewdistrictair> pageInfo=new PageInfo<>(list);
            return pageInfo;
        }else{
            List<Viewdistrictair> list=mapper2.selectByExample(example);
            PageInfo<Viewdistrictair> pageInfo=new PageInfo<>(list);
            return pageInfo;
        }

    }

    @Override
    public Airqualityindex SelectByid(Integer id) {
        return mapper1.selectByPrimaryKey(id);
    }

    @Override
    public int UpdateAir(Airqualityindex airqualityindex) {
        return mapper1.updateByPrimaryKeySelective(airqualityindex);
    }

    @Override
    public int AddAir(Airqualityindex airqualityindex) {
        return mapper1.insertSelective(airqualityindex);
    }

    @Override
    public int DeleteAir(Integer id) {
        return mapper1.deleteByPrimaryKey(id);
    }
}
